function [mean_fluo]=check_widefield_illumination(exp, nfta)
% hacks the load_vid_data function such that nfta specifies how many frames
% to load. Displays the average fluorescence of the whole frame widefield image

% watch file location

if nargin < 2
    nfta = 100
end

file_name=['D:\tmpData Behavior\widefield M105\S1-T' num2str(exp) '.vid'];

meta_info_size=4;
little_endian=0;

[fi, message] = fopen(file_name, 'r', 'ieee-le');

meta_info = fread(fi, meta_info_size, 'double');
size_y=meta_info(3);
size_x=meta_info(4);

fseek(fi, 0, 'eof');
file_size = ftell(fi);
fclose(fi);

fi = fopen(file_name, 'r', 'ieee-le');

vdata=zeros(size_x,size_y,nfta);
vmeta_info=zeros(meta_info_size,nfta);

for ind=1:nfta
    vmeta_info(:,ind) = fread(fi, meta_info_size, 'double');
    vdata(1:size_x,1:size_y,ind)=reshape(fread(fi,size_x*size_y,'int16=>int16'),size_y,size_x)';
end

mean_fluo=mean(mean(mean(vdata)));
disp(['The mean fluorescence of Exp ' num2str(exp) ' from frame 1:' num2str(nfta) ' is ' num2str(mean_fluo)])